<?php 
include 'conf/configuracion_idioma.php';
include 'conf/common_index.php';
include 'template_include_index.php';
?>
<?php $title = gettext("Encontrá lo que estás buscando")?>
<?php $descripcion = gettext("Encontrá lo que estás buscando")?>
<?php $keywords = gettext("Encontrá lo que estás buscando")?>

<?php include 'template_header_index.php';?>
<?php include 'template_nav_bar_index.php';?>
<?php include 'template/recurso_zebra_pagination_css.php'?>

<?php 

	// how many records should be displayed on a page?
	$records_per_page = 8;

	if (isset($_GET['categoria_id'])){
		// include the pagination class
		require 'zebra-pagination/Zebra_Pagination_URL_Y_GET.php';

		// instantiate the pagination object
		$pagination = new Zebra_Pagination_URL_Y_GET();

	} else {
		// include the pagination class
		require 'zebra-pagination/Zebra_Pagination_Original.php';

		// instantiate the pagination object
		$pagination = new Zebra_Pagination_Original();
	}

	$query = isset($_GET['query']) ? $_GET['query'] : null;
	$categoria_id = isset($_GET['categoria_id']) ? $_GET['categoria_id'] : null;
	$tipo_cat = isset($_GET['tipo_cat']) ? $_GET['tipo_cat'] : null;
	$orden = isset($_GET['orden']) ? $_GET['orden'] : null;

	$filtro_con_ciudad = false;

	if (!empty($query) AND !empty($categoria_id)){
		$sql = buscar_por_query_categoria_todo_el_pais($query, $categoria_id, $tipo_cat, $pagination, $records_per_page, $orden);
	} else{
		if (!empty($query) AND empty($categoria_id)){
			$sql =  buscar_por_query_todo_el_pais($query, $pagination, $records_per_page, $orden);
		} else{
			if (!empty($categoria_id) AND empty($query)){
				$sql = buscar_por_categoria_todo_el_pais($categoria_id,$tipo_cat, $pagination, $records_per_page, $orden);
			} else {
				$sql =  buscar_todo_el_pais($pagination, $records_per_page, $orden);
			}
		}
	}


	// if query could not be executed
	if (!($result = @mysql_query($sql))) {

		// stop execution and display error message
		die(mysql_error());

	}

	// fetch the total number of records in the table
	$rows = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS() AS rows'));

	
	if ($rows['rows'] == 0){
	
		$filtro_con_ciudad = false;
	
		if (!empty($query) AND !empty($categoria_id)){
			$sql = buscar_por_query_categoria_todo_el_pais($query, $categoria_id, $tipo_cat, $pagination, $records_per_page, $orden);
		} else{
			if (!empty($query) AND empty($categoria_id)){
				$sql =  buscar_todo_el_pais($pagination, $records_per_page, $orden);
			} else{
				if (!empty($categoria_id) AND empty($query)){
					$sql = buscar_por_categoria_todo_el_pais($categoria_id,$tipo_cat, $pagination, $records_per_page, $orden);
				} else {
					$sql =  buscar_todo_el_pais($pagination, $records_per_page, $orden);
				}
			}
		}
	
	
		// if query could not be executed
		if (!($result = @mysql_query($sql))) {
	
			// stop execution and display error message
			die(mysql_error());
	
		}
	
		// fetch the total number of records in the table
		$rows = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS() AS rows'));
		
	}
	
	
	// pass the total number of records to the pagination class
	$pagination->records($rows['rows']);

	// records per page
	$pagination->records_per_page($records_per_page);


	$result = mysql_query($sql);

	?>


<div class="container">
<div class="row">
	<div class="col-md-12">
		
	<section class="margin-top">   			
			<?php include 'adsense_resultado_arriba.php'?>	
   </section>
	
	<section class="margin-top">
       <p class="slogan text-center"><span><strong>
       <?php if (isset($_GET['categoria_id'])){
			$categoria =  get_categoria($_GET['categoria_id'],$tipo_cat);
			echo gettext("Resultados de"). " " .$categoria['nombre'];
		} else {
			echo gettext("Resultados de"). " " .$query;
		}?>
		</strong></span></p>
   </section>  
   
   <section class="margin-bottom">
   	
	    <?php 
	    $cant = 1;
		while ($publicacion = mysql_fetch_array($result)){
			$encontro = true;
			$imagen_path = get_image_thumb_path($publicacion['publicacion_id']);
			$imagenTipoUsuario = getPathImagenTipoUsuario($publicacion['usuario_id']);
			$publicacionId = $publicacion['publicacion_id'];
			$ciudad = get_valores_ciudad($publicacion['ciudad_id'], array("nombre"));	
			$alt = clean_string_with_spaces($publicacion['titulo']);	
			$publicacionPath =  getPublicacionPath($publicacionId);
			$cant = $cant + 1;
		?>
				<div class="col-md-6">	
				  <?php include 'content_box_default_list.php';?>
			   	</div>		
		  
		<?php }?>
	
	<div class="col-md-12 text-center">
	<?php $pagination->render();?>
	</div>	
   
   	</section>
   	
   	  <?php include 'adsense_resultado_medio.php';?>
   
   </div>
   
   
    <section class="margin-top">
        <p class="lead lead-lg text-center primary-color margin-bottom"><strong><?php echo gettext("Compra - Venta - Anuncios Clasificados Gratis en")?> <?php echo PAIS?></strong></p>
   </section>
   
 </div> 
   
</div>

<?php include 'template_footer_index.php';?>

<?php include 'template_sidebar_index.php';?>


<!-- Scripts -->
<!-- Compiled in vendors.js -->
<!--
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/imagesloaded.pkgd.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/bootstrap-switch.min.js"></script>
<script src="assets/js/wow.min.js"></script>
<script src="assets/js/slidebars.min.js"></script>
<script src="assets/js/jquery.bxslider.min.js"></script>
<script src="assets/js/holder.js"></script>
<script src="assets/js/buttons.js"></script>
<script src="assets/js/jquery.mixitup.min.js"></script>
<script src="assets/js/circles.min.js"></script>
<script src="assets/js/masonry.pkgd.min.js"></script>
<script src="assets/js/jquery.matchHeight-min.js"></script>
-->

<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/vendors.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/funcionesjs.js"></script>

<!-- Syntaxhighlighter -->
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/syntaxhighlighter/shCore.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/syntaxhighlighter/shBrushXml.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/syntaxhighlighter/shBrushJScript.js"></script>

<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/app.js"></script>
<script src="http://<?php echo DOMINIO_BASE_COMPLETO?>/js/index.js"></script>

</body>

</html>
